
#ifndef _ID_CARD_2_H_
#define _ID_CARD_2_H_
#include <stdint.h>
#include "rfid_interface.h"
#define SAMPLE_FREQ			RFID_ITF_COLLECT_FREQ
#define SAMPLE_PER_BIT		(64 * SAMPLE_FREQ / 125000)

//	#define RFID_ITF_COLLECT_FREQ 	SAMPLE_FREQ
#define ID_HEADER_BIT_NUM				9													//头数据位数量
#define ID_DATA_BIT_NUM					5													//数据位数量
#define ID_DATA_BUF_LEN					11													//数据缓冲数量
#define ID_BIT_PERIOD_64				512													//位周期
#define ID_BIT_PERIOD_32				256													//位周期
#define ID_BIT_PERIOD_16				128													//位周期
#define ID_FPERIOD_NUM(bit_period)		(bit_period / (1000000 / RFID_ITF_COLLECT_FREQ))	//全周期数量
#define ID_HPERIOD_NUM(bit_period)		(ID_FPERIOD_NUM(bit_period) / 2)					//半周期数量
#define ID_ALLOW_VALUE(bit_period)		(ID_HPERIOD_NUM(bit_period) * 50 / 100)				//允许的偏差值 50%
#define ID_CENTRAL_VALUE_REF_NUM		128													//128个数据周期作为电压中心值参考

typedef struct{
	uint16_t 	fperiod_num;	//全周期数量
	uint16_t	hperiod_num;	//半周期数量
	uint16_t	allow_value;	//允许的偏差值
	
	uint8_t 	hperiod_cnt;	//半周期计数
	uint8_t 	level;			//电平
	uint8_t 	hp_bit_cnt;		//半周期位的计数 1~8
	uint8_t		hp_bit_data;	//半周期位数据 一个bit代表一个半周期位
}manchester_decode_t;

typedef struct{
	manchester_decode_t mdecode;
	uint8_t 			header;
	uint8_t 			data[ID_DATA_BUF_LEN];
	uint8_t				row_index;
	uint8_t				column_index;
	uint8_t				recv_done;
}id_card_decode_t;


int id_card_get(uint8_t uid[5]);
//	void id_card_data_decode(uint16_t *value, uint16_t len);
int id_card_data_decode3(uint16_t *data, uint16_t len);
void id_card_reset(void);


#endif

